var actcouponbill = require('../../../../xc/model/coupon_cont')
Component({
  options: {
    addGlobalClass: true,
    multipleSlots: true
  },
  /**
   * 组件的属性列表
   */
  properties: {
     themcolor:Object,
  },

  /**
   * 组件的初始数据
   */
  data: {
    showmore: false,
    isload: true,
    modellist: [],
    isinit: false,
    actcoupon: null,
    orderinfo:null
  },
  /**
   * 组件的方法列表
   */
  methods: {
    couponshow() {
      this.triggerEvent('click', {})
    },
    initcoupon(orderinfo) {
     this.data.orderinfo= orderinfo
      //初始化优惠券
      this.getdata();
    },
    showinfo(userinfo, proids) {
      this.setData({ showmore: true })
      if (this.data.isinit == false) {
        this.getdata();
      }
    },
    morecoupon() {
      this.setData({ showmore: !this.data.showmore })
    },
    selecteditem(e) {
      var actcoupon = this.data.actcoupon
      var dataset = e.currentTarget.dataset
      var item = dataset.item

      if (actcoupon == null || actcoupon.bindid != item.bindid) {
        this.setData({ actcoupon: item })

      }
      else {
        this.setData({ actcoupon: null })
      }
      this.blackdadta();
    },
    clearselected(){
      this.setData({ actcoupon: null })
      this.blackdadta();
    },
    //回调选择数
    blackdadta(){
      
      this.triggerEvent('couponblack',  this.data.actcoupon)
      this.setData({ showmore: false })

    },
    getdata() {
      var that = this;
      that.setData({ isload: true, isinit: true })
      actcouponbill.mycoupon().then(res => {
        if (res["status"] == 1) {
          var modellist = [];
          if (res["obj"]) {
            var temobj = res["obj"];
            var ilen = temobj.length
             if(ilen>0){
              modellist=  actcouponbill.vlidEffective(temobj,that.data.orderinfo)
              ilen=modellist.length
              for (var i = 0; i < ilen; i++) {
                if(modellist[i].cid==1)
                {             
                modellist[i].val = modellist[i].val 
              }
              else
              {
                modellist[i].val = modellist[i].val 
              }
                modellist[i].fullmoney = modellist[i].fullmoney 
              }
             }
          }
          else {
          }
          that.setData({ isload: false, modellist: modellist })
        }
      })
    }
  }
})
